<template>
  <div>
    <el-container style="height: 100%;border: 1px solid #eee">
      <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
        <el-menu :default-openeds="['1', '3']" :collapse-transition="false">
          <el-submenu index="1">
            <template slot="title"><i class="el-icon-user-solid"></i>
              用户管理
            </template>
            <el-menu-item-group>
              <el-menu-item index="1-1"><i class="el-icon-search"></i>
                <router-link :to="{name:'UserList'}" class="a">用户列表</router-link>
              </el-menu-item>
              <el-menu-item index="1-2"><i class="el-icon-circle-plus-outline"></i>
                <router-link :to="{name:'UserAdd'}" class="a">添加用户</router-link>
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-menu-item index="2">
            <i class="el-icon-document"></i>
            <span slot="title">
              <router-link :to="{name:'ArticleList'}" class="a">文章列表</router-link>
            </span>
          </el-menu-item>
          <el-menu-item index="3">
            <i class="el-icon-document"></i>
            <span slot="title"><router-link :to="{name:'CommentList'}" class="a">评论列表</router-link></span>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <el-container>
        <el-header style="text-align: right; font-size: 12px">
          <span>管理员</span>
          <span>{{username}}</span>
        </el-header>

        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>

    </el-container>
    <Identity ref="legal"></Identity>
  </div>
</template>

<script>
import Identity from './identity'
export default {
  name: 'Admin',
  components: {Identity},
  data () {
    return {
      id: sessionStorage.getItem('id'),
      username: '无昵称'
    }
  },
  mounted () {
    this.$refs.legal.isLegal()
    this.getUserName()
  },
  methods: {
    getUserName () {
      var that = this
      this.axios({
        url: 'http://localhost:8080/linearAlgebra/findById',
        method: 'post',
        data: {
          id: that.id
        }
      }).then(function (response) {
        if (response.data.length === 0) {
        } else {
          that.username = response.data.username
        }
      })
    }
  }
}
</script>

<style scoped>
  .el-header {
    background-color: #66b1ff8a;
    color: #333;
    line-height: 60px;
  }
  .el-menu{
    height:100vh
  }

  .el-aside {
    color: #333;
  }
  .a {
    text-decoration: none;
  }
</style>
